#include<bits/stdc++.h>
using namespace std;

string operator+ (string& a, string& b){
    if(!a.length() && !b.length())return "0";
    string ans;
    int i = a.length() - 1, j = b.length() - 1, carry = 0;
    while(i >= 0 && j >= 0){
        ans += ((a[i] - '0' + b[j] - '0' + carry) % 10) + '0';
        carry = (a[i] - '0' + b[j] - '0' + carry) / 10;
        i--;
        j--;
    }
    while(i >= 0){
        ans += ((a[i] - '0' + carry) % 10) + '0';
        carry = (a[i] - '0' + carry) / 10;
        i--;
    }
    while(j >= 0){
        ans += ((b[j] - '0' + carry) % 10) + '0';
        carry = (b[j] - '0' + carry) / 10;
        j--;
    }
    if(carry) ans+= '1';
    reverse(ans.begin(), ans.end());
    return ans;
}

bool judge(string a, string b, string& num){
    if(a.length() + b.length() == num.length())return false;
    int pos = a.length() + b.length(); //标记从哪里开始取结果
    while(pos < num.length()){
        string s_ans = a + b;
        if(num.length() < s_ans.length() + pos || num.substr(pos, s_ans.length()) != s_ans)return false;
        a = b;
        b = s_ans;
        pos += s_ans.length();
    }
    return true;
}

class Solution {
public:
    bool isAdditiveNumber(string num) {
        if(num.length() < 2)return false;
        for(int len1 = 1; len1 + 1 < num.length(); len1++){
            for(int len2 = 1; len2 + 1 < num.length(); len2++){
                if(num[len1] == '0' && len2 > 1)break;
                if(judge(num.substr(0, len1), num.substr(len1, len2), num))return true;
            }
        }
        return false;
    }
};

/**
 * 2022.1.10
 * 写个大数加法
 * 只需要枚举前连个数就可以，后面的答案都是固定的
 */